import java.util.Arrays;
import java.util.Random;

public class Aleat {
    private int[] a,aSort;
    boolean sorted=false;
    int n,lim;
    Aleat(){}
    Aleat (int n, int lim){
        this.n=n;
        this.lim=lim;
        a =new int[n];
        Random random = new Random();
        for (int i = 0; i < n; i++)
            a[i]=random.nextInt(lim);
        System.out.println(Arrays.toString(a));
    }
    public int getValeur (int n){
        if(sorted==false){
            sorted=true;
            aSort=new int[this.n];
            for (int i = 0; i < this.n; i++)
                aSort[i]=a[i];
            Arrays.sort(aSort);
        }
        return aSort[n];
    }
    public int[]getValeurs(){
        return this.a;
    }
    public int[]histo(){
        int his[]=new int[lim];
        for (int i = 0; i < n; i++)
            ++his[a[i]];
        System.out.println(Arrays.toString(his));
        return his;
    }
    public static void main(String[] args) {
        int n=5,lim=20;
        Aleat aleat=new Aleat(n,lim);
        for (int i = 0; i < n; i++)
            System.out.printf("%3d",aleat.getValeur(i));
        System.out.println();
        aleat.histo();
    }
}